﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Pahan.McuFusion.Common;
using Pahan.McuFusion.UI.Interfaces.NewWorkspaceWizardPages;

namespace Pahan.McuFusion.UI.Views.NewWorkspaceWizardPages
{
    public partial class HardwareInterfacePage : UserControl, IHardwareInterfacePage
    {
        public HardwareInterfacePage()
        {
            InitializeComponent();
        }

        #region Implementation of IWizardPage

        /// <summary>
        /// Gets the title of the page.
        /// </summary>
        public string Title
        {
            get
            {
                return "Hardware Interface";
            }
        }

        #endregion

        #region Implementation of IHardwareInterfacePage

        /// <summary>
        /// Shows the list of the available interfaces.
        /// </summary>
        public void ShowInterfaces(IList<HardwareInterfaceInfo> interfaces)
        {
            lstHardwareInterfaces.Items.Clear();
            foreach (var info in interfaces)
            {
                lstHardwareInterfaces.Items.Add(info);
            }
            if (lstHardwareInterfaces.Items.Count > 0)
            {
                lstHardwareInterfaces.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// Gets the selected interface.
        /// </summary>
        public HardwareInterfaceInfo SelectedInterface
        {
            get
            {
                return lstHardwareInterfaces.SelectedItem as HardwareInterfaceInfo;
            }
        }

        public event EventHandler SelectedInterfaceChanged;

        #endregion

        private void lstHardwareInterfaces_SelectedIndexChanged(object sender, EventArgs e)
        {
            var handler = SelectedInterfaceChanged;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }
}
